package com.badlogic.androidgames.mypirates;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;


import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.framework.Input.TouchEvent;
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.mypirates.Sprite.MySprite;

public class MainMenuScreen extends Screen {

	Typeface font;
	Paint paint;
	ArrayList<MenyEntry> menuEntries;
	
	public MainMenuScreen(Game game) {
		super(game);
		font = Typeface.createFromAsset(game.getAssetManager(), "pericl.ttf");
		//font = Typeface.create(Typeface.DEFAULT, Typeface.BOLD);
		paint = new Paint();
		paint.setTypeface(font);
		paint.setTextSize(40);
		paint.setColor(Color.YELLOW);
		paint.setAntiAlias(true);
		
		menuEntries = new ArrayList<MenyEntry>();
		menuEntries.add(new MenyEntry("Start", paint,0,0));
		
	}

	@Override
	public void update(float deltaTime) {
		// TODO Auto-generated method stub
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		HandleInput(touchEvents);	
	}

	private void HandleInput(List<TouchEvent> touchEvents) {
		for(TouchEvent event : touchEvents){
			if(event.type == TouchEvent.TOUCH_UP){
				for(MenyEntry m : menuEntries){
					if(inBounds(event, m.position.left, m.position.top, m.position.width(), m.position.height())){
						game.setScreen(new SinglePlayerGameScreen(game));
					}
				}
				//game.setScreen(new SinglePlayerGameScreen(game));
			}
				
		}
	}

	@Override
	public void draw(float deltaTime) {
		Graphics g = game.getGraphics();
		for(MenyEntry m : menuEntries){
			m.draw(g);
		}
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
	
	private boolean inBounds(TouchEvent event, int x, int y, int width, int height) {
        if(event.x > x && event.x < x + width - 1 && 
           event.y > y && event.y < y + height - 1) 
            return true;
        else
            return false;
    }
}
